package com.flying.invest.assets.spider;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.Service;
import com.flying.framework.model.ModelFactory;

@Service(value="Fund", desc="东方财富价格抓取")
public class EastMoneyFundPriceSpider implements IPriceSpider {

	public SpiderPrice fetch(@Param(value="code", required=true, desc="证券代码") String code) throws Exception {
		Double price = null;
		String url = this.getUrl(code);
		Document document=Jsoup.connect(url).get();
		Elements eles = document.getElementsByClass("dataNums");
		Element fundEle = eles.get(1).child(0);
		if(fundEle != null) {
			 price = Double.parseDouble(fundEle.text());
		}
		return ModelFactory.create(SpiderPrice.class, SpiderPrice.PRICE, price, SpiderPrice.URL, url);
	}

	public String getUrl(String code) {
		return "http://fund.eastmoney.com/"+code+".html";
	}
}
